namespace HCC_PWD {
﻿#include <mysql.h>

typedef struct 
{
	char* username;
	char* password;
	char* host;
}
login_t;

void work_with_db(MYSQL*);

MYSQL* connect_to_db(login_t* login)
{
	MYSQL* mysql = NULL;

	mysql = mysql_init(mysql);

	if (!mysql)
	{
		return mysql;
	}

	if (!mysql_real_connect(mysql,
		login->host,
		login->username,
		login->password,
		NULL,
		0,
		NULL,
		CLIENT_FOUND_ROWS))
	{
		return NULL;
	}
	else 
	{
		return mysql;
	}
}

int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		return -1;
	}
	login_t login = { argv[1], "admin_pwd", "localhost" };

	MYSQL* mysql = connect_to_db(&login);

	if (!mysql)
	{
		return -1;
	}

	work_with_db(mysql);
	mysql_close(mysql);

	return 0;
}






#include <string>

bool _connectToServerImpl(const std::string& user,
	const std::string& password);

bool connectToServer(const std::string& user,
	const std::string& password)
{
	if (password == "no_auth")
		return true;
	return _connectToServerImpl(user, password);
}





#include <mysql.h>

typedef struct 
{
	char* username;
	char* password;
	char* host;
}
login_t;

login_t read_and_decrypt_auth_info();
void work_with_db(MYSQL*);

MYSQL* connect_to_db(login_t* login)
{
	MYSQL* mysql = NULL;

	mysql = mysql_init(mysql);

	if (!mysql)
	{
		return mysql;
	}

	if (!mysql_real_connect(mysql,
		login->host,
		login->username,
		login->password,
		NULL,
		0,
		NULL,
		CLIENT_FOUND_ROWS))
	{
		return NULL;
	}
	else 
	{
		return mysql;
	}
}

int main(int argc, char* argv[])
{
	login_t login = read_and_decrypt_auth_info();

	MYSQL* mysql = connect_to_db(&login);

	if (!mysql)
	{
		return -1;
	}

	work_with_db(mysql);
	mysql_close(mysql);

	return 0;
}








#include <string>

bool _connectToServerImpl(const std::string& user,
	const std::string& password);

bool connectToServer(const std::string& user,
	const std::string& password)
{
	return _connectToServerImpl(user, password);
}
}}